/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2015.07.13                                          *
 * Description:      an implement to input database for using map type   *
 *                                                                       *
 *************************************************************************/

#ifndef FreeMAPs_include_COMMON_tbox_MapDatabase_h
#define FreeMAPs_include_COMMON_tbox_MapDatabase_h

#include "FreeMAPsConfig.h"

//C++ headers
#include <string>
#include <set>
#include <map>

//COMMON headers
#include "COMMON/enum/DataType.h"

namespace FreeMAPs
{

/**
 * @brief MapDatabase used to deal the map data to implement the InputDatabase.
 *
 * in the InputDatabase, the type of std::map<Key, Value> is not supported.
 * so we implement an object to deal this.
 */
class MapDatabase
{
public:

    MapDatabase();
    ~MapDatabase();

public:

    inline bool
    key_exists (
        const std::string& key) const;

    inline DataType
    get_key_type (
        const std::string& key) const;

public:

    std::set<std::string>
    get_keys() const;

    /**
     * Return whether the specified key represents a string-string map entry.  If
     * the key does not exist, then false is returned.
     */
    bool
    is_string_string_map(
        const std::string& key) const;

    /**
     * Create a complex vector entry in the database with the specified
     * key name.  If the key already exists in the database, then the old
     * key record is deleted and the new one is silently created in its place.
     */
    void
    put_string_string_map(
        const std::string& key,
        const std::map<std::string, std::string>& data);

    /**
     * Get a complex entry from the database with the specified key
     * name.  If the specified key does not exist in the database or
     * is not a complex vector, then an error message is printed and
     * the program exits.  Complex values may be promoted from integers,
     * floats, or doubles.
     */
    std::map<std::string, std::string>
    get_string_string_map(
        const std::string& key) const;

private:

    /*
     * map<key, map<x, y> >
     */
    std::map<std::string, std::map <std::string, std::string> > d_string_string_maps;
};

}

#include "COMMON/tbox/MapDatabase.inl"

#endif
